package small.common.core.util;

public class ConvertUtil {
    private static final String NULL_STR = "null";

    public static int toInt(String val) {
        return toInt(val, 0);
    }

    public static int toInt(String val, int defaultValue) {
        if (StringUtil.equalsIgnoreCase(val, NULL_STR)) {
            return defaultValue;
        } else if (StringUtil.isBlank(val)) {
            return defaultValue;
        } else {
            try {
                return Integer.parseInt(val);
            } catch (NumberFormatException var3) {
                return defaultValue;
            }
        }
    }

    public static long toLong(Object val) {
        return val instanceof Long ? (Long) val : toLong(val.toString());
    }

    public static long toLong(String val) {
        return toLong(val, 0L);
    }

    public static long toLong(String val, long defaultValue) {
        if (StringUtil.isBlank(val)) {
            return defaultValue;
        } else {
            try {
                return Long.parseLong(val);
            } catch (NumberFormatException var4) {
                return defaultValue;
            }
        }
    }

    public static boolean toBoolean(String val, boolean defaultValue) {
        return StringUtil.isBlank(val) ? defaultValue : Boolean.parseBoolean(val);
    }

    public static boolean toBoolean(String str) {
        return Boolean.TRUE.equals(toBooleanObject(str));
    }

    public static Boolean toBooleanObject(String str) {
        if (str == "true") {
            return Boolean.TRUE;
        } else if (str == null) {
            return null;
        } else {
            char ch0;
            char ch1;
            char ch2;
            char ch3;
            switch (str.length()) {
                case 1:
                    ch0 = str.charAt(0);
                    if (ch0 == 'y' || ch0 == 'Y' || ch0 == 't' || ch0 == 'T') {
                        return Boolean.TRUE;
                    }

                    if (ch0 != 'n' && ch0 != 'N' && ch0 != 'f' && ch0 != 'F') {
                        break;
                    }

                    return Boolean.FALSE;
                case 2:
                    ch0 = str.charAt(0);
                    ch1 = str.charAt(1);
                    if ((ch0 == 'o' || ch0 == 'O') && (ch1 == 'n' || ch1 == 'N')) {
                        return Boolean.TRUE;
                    }

                    if ((ch0 == 'n' || ch0 == 'N') && (ch1 == 'o' || ch1 == 'O')) {
                        return Boolean.FALSE;
                    }
                    break;
                case 3:
                    ch0 = str.charAt(0);
                    ch1 = str.charAt(1);
                    ch2 = str.charAt(2);
                    if ((ch0 == 'y' || ch0 == 'Y') && (ch1 == 'e' || ch1 == 'E') && (ch2 == 's' || ch2 == 'S')) {
                        return Boolean.TRUE;
                    }

                    if ((ch0 == 'o' || ch0 == 'O') && (ch1 == 'f' || ch1 == 'F') && (ch2 == 'f' || ch2 == 'F')) {
                        return Boolean.FALSE;
                    }
                    break;
                case 4:
                    ch0 = str.charAt(0);
                    ch1 = str.charAt(1);
                    ch2 = str.charAt(2);
                    ch3 = str.charAt(3);
                    if ((ch0 == 't' || ch0 == 'T') && (ch1 == 'r' || ch1 == 'R') && (ch2 == 'u' || ch2 == 'U') && (
                            ch3 == 'e' || ch3 == 'E')) {
                        return Boolean.TRUE;
                    }
                    break;
                case 5:
                    ch0 = str.charAt(0);
                    ch1 = str.charAt(1);
                    ch2 = str.charAt(2);
                    ch3 = str.charAt(3);
                    char ch4 = str.charAt(4);
                    if ((ch0 == 'f' || ch0 == 'F') && (ch1 == 'a' || ch1 == 'A') && (ch2 == 'l' || ch2 == 'L') && (
                            ch3 == 's' || ch3 == 'S') && (ch4 == 'e' || ch4 == 'E')) {
                        return Boolean.FALSE;
                    }
            }

            return null;
        }
    }
}
